<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <Meta charset="UTF-8">
    <link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
    <script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
    <Meta http-equiv="X-UA-Compatible" content="IE=edge">
    <Meta name="vIEwport" content="wIDth=device-wIDth, initial-scale=1.0">
    <Title>document</Title>
    <link rel="stylesheet" href="./register.css">
    <%--<script src="./Js/register.Js"></script>--%>
    <style type="text/css">
        ::-webkit-input-placeholder {
            color: #2b2b2b;
        }
        #s1{
            text-align: center;
            color: #0f0f0f;
        }
        #uuId{
            color: #ac2925;
        }
        #message{
            color: #ac2925;
        }
    </style>
    <script type="text/javascript">
        $(function (){
            $(".d1").keydown(function (event){
                if (event.keyCode == 13){
                    $("#btn1").click();
                }
            })
            $("#btn1").click(function () {
                var username = $.trim($("#username").val());
                var password = $.trim($("#password").val());
                var password1 = $.trim($("#password1").val());
                var name = $.trim($("#name").val());
                var email = $("#email").val();
                // alert(username);
                // alert(password1);
                // alert(name)

                if (name == ""){
                    alert("请填写用户名");
                    return;
                }else {
                    if (!(/[\u4e00-\u9a40]/.test(name))) {
                        alert("你妈给你取名字就瞎取《?》  "+name+" 人叫的？")
                        return;
                    }
                }
                if (name.length < 2 || name.length >= 4){
                    alert("名字能在短一点妈  ");
                    return;
                }
               /* if(username !="") {
                    if (!(/^[0-9]*$/.test(username)) && !/^[a-z]+$/.test(username)){
                        alert("这样的账号你能记住吗？   不要瞎敲了哥！")
                        return;
                    }
                }*/
                if (username == ""){
                    alert("账号可以不填？");
                    return;
                }
                if(username !="") {
                    if (!(/^\w+$/.test(username))) {
                        alert("这样的账号你能记住吗？   不要瞎敲了哥！")
                        return;
                    }
                }
                if (username.length < 6 || username.length > 14){
                    alert("6————14  能懂？");
                    return;
                }
                if(email!="") {
                    if (!(/^(\w|\d)+@\w+\.com$/.test(email))) {
                        alert("邮箱格式错误！！ 应为 *@*.com ,不会填就不用填了呗 听不懂人话 我还不知道你的智商<?> buding!!")
                        return;
                    }
                }
                if (username == "" || password == "" || password1 == ""){
                    alert("请补全账号或密码");
                    return;
                }
                if(password !="") {
                    if (!(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/.test(password))) {
                        alert("密码格式错误 密码只能由大小写字母和数字结合组成 字数不屑 比如:nie123")
                        return;
                    }
                }
                if (password1 != password){
                    alert("前后密码不一致，你是不是眼瞎！！么了你念不成")
                    return;
                }
                // alert("你好");
                $("#username").val("");
                $("#password").val("");
                $("#password1").val("");
                $("#name").val("");
                $("#email").val("");
                $.ajax({
                    url:'saveRegister.do',
                    data:{
                        loginAct:username,
                        loginPwd:password1,
                        name:name,
                        email:email
                    },
                    type:'post',
                    dataType:'json',
                    success:function (data) {
                        if (data.code == "1"){
                            var UUId = data.retData;
                            $("#uuId").text('NJH已为你创建好全球唯一ID :'+UUId)
                            // alert(UUId);
                            var message = data.message;
                            $("#message").text(message)
                            // alert(data.message);
                            $("#username").val("");
                            $("#password").val("");
                            $("#password1").val("");
                            $("#name").val("");
                            $("#email").val("");
                        }
                        if(data.code == "0"){
                            alert(data.message);
                        }
                    }
                })

            })

        })
    </script>
</head>
<body class="body">

<div class="d1">
    <div class="d2">
        <h1 class="h1">立即注册</h1>
        <table class="t1">
            <tr class="tr1" >
                <td class="td1">用户名</td>
            </tr>
            <tr class="tr1">
                <td class="td2"><input class="inp"  name="text" type="text" name="name" id="name" placeholder="要中文(2 3个)"></td>
            </tr>
            <tr class="tr1">
                <td class="td1">登录账号</td>
            </tr>
            <tr class="tr1">
                <td class="td2"><input class="inp" type="text"  name ="username" id="username" placeholder="字母或数字(>5 <14)"></td>
            </tr>
            <tr class="tr1">
                <td class="td1">性别</td>
            </tr>
            <tr class="tr1">
                <td class="td2"><input class="inp" type="radio" name="sex" value="man">男 <input  type="radio" name="sex" value="women">女</td>
            </tr>
            <tr class="tr1">
                <td class="td1">邮箱地址</td>
            </tr>
           <%-- <tr class="tr1">
                <td class="td2"><input class="inp" type="file" name="file" ID="file" value="touxiang"></td>
            </tr>--%>
            <tr class="tr1">
                <td class="td2"><input class="inp" type="text" name="email" id="email"  placeholder="注册可以不填"></td>
            </tr>
            <tr class="tr1">
                <td class="td1">密码</td>
            </tr>
            <tr class="tr1">
                <td class="td2"><input class="inp" type="password" id="password" name="password" placeholder="密码为数字和字母的组合"></td>
            </tr>
            <tr class="tr1">
                <td class="td1">再次输入</td>
            </tr>
            <tr class="tr1">
                <td class="td2"><input class="inp" type="password" id="password1" name="password1" placeholder="再次输入密码需一致"></td>
            </tr>
            <tr class="tr1">
                <td class="td2"><button type="button" name="sub" class="sub" id="btn1">注册</button></td>
            </tr>
        </table>
    </div>
    <div class="d3">
        <span id="s1">本人专注后端开发，页面实属不会</span><br>
        <span id="s1">请大家谅解！！！</span>  <span>一个帐号只能创建一次 否则会出现登录异常 请按F12及时观察，报告我，希望你能发现这段话</span>
        <div class="d4">已有账号？</div>
        <div class="d5">有账号就登陆吧，好久不见了<br>
          <%--  注册成功！小聂为您创建了一个全球绝对唯一ID:  <span id="uuId" ></span>--%>
            <span id="message" ></span><br>
            <span id="uuId" ></span>
        </div>
       <%-- <div class="d6" id="uuId">注册成功！小聂为您创建了一个全球绝对唯一ID:</div>--%>
        <form>
            <div class="d6"><button type="submit" name="sub" class="sub2" onclick="window.open('settings/qx/user/tologin.do')">登录</button></div>
        </form>
    </div>
</div>
<%--
<script>
  function check(){
        var email = document.getElementById("email").value;
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        var password2 = document.getElementById("password1").value;
        var sex;
        var sexObj =document.getElementsByName("sex")
        for(var i=0;i<sexObj.length;i++){
            if(sexObj[i].checked){
                sex = sexObj[i].value;
            }
        }
        // 邮箱验证
        if(email!=""){
            if(!(/^(\w|\d)+@\w+\.com$/.test(email))){
                alert("邮箱格式错误")
                return;
            }
            else {
                console.log("email true");
                // 邮箱验证通过，进入用户名验证
                if(username !=""){
                    if(username.length>5){
                        alert("用户名格式错误")
                        return;
                    }
                    else {
                        console.log("username true");
                        // 用户名验证通过，进行密码验证
                        if(password !=""){
                            if(!(/^(?![^a-zA-Z]+$)(?!\D+$)/.test(password))){
                                alert("密码格式错误")
                                return;
                            }
                            else {
                                console.log("password true");
                                if(password == password2){
                                    localstorage.setItem("username",username);
                                    localstorage.setItem("email", email);
                                    localstorage.setItem("password",password);
                                    localstorage.setItem("sex", sex);

                                    window.open("login.HTML")
                                }
                                else{
                                    alert("密码验证错误，请核对密码")
                                    return;
                                }
                            }
                        }
                        else{
                            alert("密码为空！")
                            return;
                        }
                    }
                }
                else{
                    alert("会员登录名为空！")
                    return;
                }
            }
        }
        else{
            alert("邮箱为空！")
            return;
        }
    }
</script>--%>
</body>
</HTML>
